{extend name="public/list_page"/}
{block name="content"}
<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-tab-content">
            <blockquote class="layui-elem-quote">
                <ul>
                    <li>登录验证码：后台登录验证码。关闭后，登录后台无需输入验证码。</li>
                    <li>询盘邮件：收到询盘消息将发送邮件到指定邮箱账号。开启后，请将SMTP服务器、SMTP端口、邮箱账号、授权码填写完整。</li>
                    <li>图片格式：允许上传的图片格式，不同格式使用英文逗号分隔。</li>
                    <li>上传文件大小：上传单个文件的大小，0为无限制。单位：字节。例:1M = 1024 * 1024 = 1048576</li>
                    <li>限制访问站点：开启后"限制访问IP"模块中的IP段将无法访问站点</li>
                </ul>
            </blockquote>
            <form id="formData" class="layui-form layui-form-pane" autocomplete="off">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-required">系统名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="system_name" value="{$info.system_name}" class="layui-input">
                    </div>
                </div>
                <!--<div class="layui-form-item">
                    <label class="layui-form-label layui-required">系统版本</label>
                    <div class="layui-input-block">
                        <input type="text" name="system_version" value="{$info.system_version}" class="layui-input">
                    </div>
                </div>-->
                <div class="layui-form-item">
                    <label class="layui-form-label">登录验证码</label>
                    <div class="layui-input-block">
                        <input
                                type="checkbox"
                                name="open_captcha"
                                lay-skin="switch"
                                lay-text="开启|关闭"
                                {if $info.login_captcha == 1} checked {/if}>
                    </div>

                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">询盘邮件</label>
                    <div class="layui-input-block">
                        <input
                                type="checkbox"
                                name="inquiry_send_email"
                                lay-filter="sendEmail"
                                lay-skin="switch"
                                lay-text="开启|关闭"
                                {if $info.inquiry_send_email == 1} checked {/if}>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">SMTP服务器</label>
                    <div class="layui-input-block">
                        <input type="text" id="smtpHost" name="smtp_host" value="{$info.smtp_host}" class="layui-input" placeholder="请输入SMTP服务器">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">SMTP端口</label>
                    <div class="layui-input-block">
                        <input type="text" id="smtpPort" name="smtp_port" value="{$info.smtp_port}" class="layui-input" placeholder="请输入SMTP端口">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱账号</label>
                    <div class="layui-input-block">
                        <input type="text" id="EmailUserName" name="email_username" value="{$info.email_username}" class="layui-input" placeholder="请输入邮箱账号">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">授权码</label>
                    <div class="layui-input-block">
                        <input type="text" id="EmailPwd" name="email_pwd" value="{$info.email_pwd}" class="layui-input" placeholder="请输入邮箱授权码">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">图片格式</label>
                    <div class="layui-input-block">
                        <input type="text" id="imgExt" name="img_ext" value="{$info.img_ext}" class="layui-input" placeholder="允许上传的图片格式，使用英文逗号分隔">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label layui-required">上传文件大小</label>
                    <div class="layui-input-block">
                        <input type="text" id="fileSize" name="file_size" value="{$info.file_size}" class="layui-input" placeholder="允许上传文件大小，单位：字节">
                    </div>
                </div>

                <!--<div class="layui-form-item">
                    <label class="layui-form-label">收件邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" id="acceptEmail" name="accept_email" value="{$info.accept_email}" class="layui-input" placeholder="请输入邮箱账号，用于接收邮件通知">
                    </div>
                </div>-->

                <!--<div class="layui-form-item">
                    <label class="layui-form-label">消息显示时长</label>
                    <div class="layui-input-block">
                        <input type="text" name="msg_time" value="{$info.msg_time}" class="layui-input" placeholder="单位毫秒，默认值3000">
                    </div>
                </div>-->

                <div class="layui-form-item">
                    <label class="layui-form-label">限制访问站点</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="forbidden" lay-skin="switch" lay-text="开启|关闭" {if $info.forbidden == 1} checked {/if}>
                    </div>

                </div>
                <div class="btn-block">
                    <button type="button" lay-submit lay-filter="sendForm" class="layui-btn layui-btn-normal"><i class="fa fa-check"></i>提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary"><i class="fa fa-refresh"></i>重置</button>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}

{block name="custom"}

{/block}

{block name="js"}
<script>
    var sendEmailFlag = false
    layui.use('form',function () {
        var $ = layui.jquery,
            form = layui.form;

        form.on('switch(sendEmail)', function (data) {
            sendEmailFlag = data.elem.checked
        })

        form.on('submit(sendForm)', function (obj) {
            let smtpHost = $('#smtpHost').val()
            let smtpPort = $('#smtpPort').val()
            let EmailUserName = $('#EmailUserName').val()
            let EmailPwd = $('#EmailPwd').val()
            let fileSize = $('#fileSize').val()
            let emailReg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
            if (sendEmailFlag) {
                if (emptyCheck(smtpHost)) {
                    hintMsg('请输入SMTP服务器', 'smtpHost')
                    return false
                } else if (emptyCheck(smtpPort)) {
                    hintMsg('请输入SMTP端口', 'smtpPort')
                    return false
                } else if (emptyCheck(EmailUserName) || !emailReg.test(EmailUserName)) {
                    hintMsg('请输入正确格式的邮箱账号', 'EmailUserName')
                    return false
                } else if (emptyCheck(EmailPwd)) {
                    hintMsg('请输入授权码', 'EmailPwd')
                    return false
                }
            }

            if (emptyCheck(fileSize)) {
                hintMsg('请输入允许上传文件大小', 'fileSize')
                return false
            }

            $.ajax({
                type: "POST",
                data: obj.field,
                url: "{:url('system/edit')}",
                dataType: "JSON",
                success: function (res) {
                    if (res.code == 'suc') {
                        sucMsg(res.msg)
                    } else {
                        errMsg(res.msg)
                    }
                }
            })
            //防止刷新
            // return false;
        })
    });
</script>
{/block}